import { http } from "@/utils/http";
import { Result } from "../types";


export type roleData = {
  roleId?: number,
  name?: string,
  status?: number,
  note?: string,
  menuIdList?: Array<number>
};

type roleSearch = {
  name: string,
  status: number,
  pageNumber: number,
  pageSize: number,
  sortName: string,
  sortType: number
}

// 角色列表
export const roleList = (params?: roleSearch) => {
  return http.request<Result>("get", "/api/Role/List", { params });
};

// 新增角色
export const addRole = (data?: roleData) => {
  return http.request<Result>("post", "/api/Role/Add", { data });
};

// 修改角色
export const updateRole = (data?: roleData) => {
  return http.request<Result>("post", `/api/Role/Update/${data.roleId}`, { data });
};

// 修改授权
export const saveAuth = ({ roleId, menuIdList }) => {
  return http.request<Result>("post", `/api/Role/UpdateMenus/${roleId}`, { data: menuIdList });
};

// 查询授权
export const getRole = (Id: number) => {
  return http.request<Result>("get", `/api/Role/Get/${Id}`, {});
};

// 删除角色
export const delRole = (Id: number) => {
  return http.request<Result>("post", `/api/Role/Delete/${Id}`, {});
};

// 查询所有角色信息
export const ListRole = () => {
  return http.request<Result>("get", "/api/User/ListRole", {});
};
